<!--问题详情-->
<template>
  <section class="page">
    <headerbar>问题详情</headerbar>

    <section class="block frame-content-sub mgt-2 pdh-4">

      <div class="user-avatar">
        <div class="avatar">
          <img src="../../../../static/images/dangjian/home/img-load-error.jpg" alt="">
        </div>
        <div class="info">
          <h1>{{detailData.questionerName}}</h1>
          <p class="text">{{getTime(detailData.createTime)}}</p>
        </div>
      </div>

        <div class="block-with-icon">
          <i class="icon">问</i>
          <h1 class="title">{{detailData.questionContext}}</h1>
        </div>

        <div class="block-with-icon" v-if="detailData.isReply==='0'">
          <i class="icon">答</i>
          <div class="cont">
            <div class="title">
            </div>
            <div class="answer-text">
              <div class="input-row-wrap">
                <textarea v-model="contents" placeholder="请输入回复内容" name="" id="" cols="30" rows="5"></textarea>
              </div>
            </div>
          </div>
        </div>
      <div class="block-with-icon" v-if="detailData.isReply==='1'">
        <i class="icon">答</i>
        <div class="cont">
          <div class="title">
            <div class="">
              <span class="color-tip">{{detailData.replayUserName}}</span>
              <span class="color-red pdh-1">回复</span>
            </div>

            <span class="color-tip tip">{{getTime(detailData.replyCreateTime)}}</span>
          </div>
          <div class="answer-text">
            {{detailData.replayContext}}
          </div>
        </div>
      </div>

      <div v-if="detailData.isReply==='0'" @click="replay()" class="default-block-btn mgh-10">确认回复</div>
    </section>

  </section>
</template>

<script>
  import tools from '@/utils/tools'
  import api from '@/common/config/api'
  import loginService from '@/service/loginService'
  import moment from 'moment'
  export default {
    name: 'tutoringVillageDetail',
    data () {
      return {
        id: '',
        detailData: {},
        contents: ''
      }
    },
    created () {
      this.id = this.$route.params.id
      this.loadData()
    },
    methods: {
      loadData () {
        loginService.getCocachSuggestInfo(this.id).then((res) => {
          if (res.code !== 0) {
            return tools.tip(res.message)
          }
          this.detailData = res.data
        })
      },
      getTime (createTime) {
        return moment(createTime).format('YYYY-MM-DD')
      },
      replay () {
        if (this.contents === '') {
          return tools.tip('请输入回复内容！')
        }
        let data = {
          coachId: this.id,
          replayContext: this.contents
        }
        loginService.replayContext(data).then((res) => {
          if (res.code !== 0) {
            return tools.tip(res.message)
          }
          tools.tip('回复成功！')
          this.loadData()
        })
      }
    }
  }
</script>

<style scoped>

</style>
